package com.springcloud.zull.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springcloud.zull.aop.LogAnnotation;
import com.springcloud.zull.entity.Activity;
import com.springcloud.zull.feign.Service1GetFeignClient;
import com.springcloud.zull.interceptor.ReturnResponseBean;
import com.springcloud.zull.mapper.ActivityMapper;
import com.springcloud.zull.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import utils.ResponseBean;

import java.util.Date;
import java.util.List;

/**
 * @author wfh
 */
@RestController
@RequestMapping("/")
@ReturnResponseBean
public class Controller {

    @Autowired
    private Service1GetFeignClient service1GetFeignClient;
    @Autowired
    private ActivityService activityService;
    @Autowired
    private ActivityMapper activityMapper;

    @GetMapping("/get")
    @LogAnnotation
    public List<Activity> get() {
        Activity activity = new Activity();
        activity.setActivityAddress("xsaxsaxsa");
        activity.setActivityTime(new Date());
        activity.setHistoryAnnouncement("擦擦擦撒初三擦");
        activityService.save(activity);
        System.err.println(activityService.getById("1224800768501268481"));
        QueryWrapper<Activity> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("history_announcement", "删");

        Page page = activityMapper.selectPage(new Page(1, 10), queryWrapper);
        Activity activity1 = activityService.getById("1224800768501268481");
        return activityService.list(queryWrapper);

    }

    @GetMapping("/update")
    @LogAnnotation
    public Integer update() {
        activityService.getById("2");
        activityMapper.deleteById(2);
        return 20;
    }

    @DeleteMapping("/delete")
    @LogAnnotation
    public void delete() {

        Activity activity = activityService.getById("1");
        activity.setIsDelete(true);
        activity.setHistoryAnnouncement("删掉了");
        activityMapper.updateById(activity);

    }

    @GetMapping("/getMyself")
    public ResponseBean getMyself() {

        return service1GetFeignClient.get();
    }

    public static void main(String[] args) {
        String str = "{\"code\":200,\"data\":\"xasnkcdskncjd女家分店凝聚到你家\",\"message\":\"操作成功!\"}";
        System.err.println();
    }
}
